package com.megurokai.paint;

import java.util.ArrayList;
import java.util.List;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;

public class Status {
	private float x;
	private float y;
	private int width;
	private int height;
	private int targetLayer;
	private Paint paint;
	private List<Layer> listLayer;
	private Status defaultStatus;
	
	public Status(){
		defaultStatus = null;
		listLayer = new ArrayList<Layer>();
		init();
		
	}
	
	public Status(Status status) {
		this();
		copy(status);
	}

	public void copy(Status status){
		setX(status.getX());
		setY(status.getY());
		setColor(status.getColor());
		setStrokeWidth(status.getStrokeWidth());
		setAlpha(status.getAlpha());
		setWidth(status.getWidth());
		setHeight(status.getHeight());
	}
	
	public void init(){
		x = 0;
		y = 0;
		width = 0;
		height = 0;
		targetLayer = 0;
		paint = new Paint();
		listLayer.clear();
		
		if(defaultStatus != null){
			copy(defaultStatus);
		}
	}
	public void reset(){
		init();
		
		Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
		addLayer(bitmap);
	}
	
	public Canvas getCanvas(){
		Canvas canvas = new Canvas(listLayer.get(targetLayer).getBitmap());
		return canvas;
	}
	public void setDefault(Status status){
		defaultStatus = new Status();
		defaultStatus.copy(status);
	}
	
	public int getColor() {
	    return paint.getColor();
	}
	public void setColor(int color) {
	    paint.setColor(color);
	}
	public float getStrokeWidth() {
	    return paint.getStrokeWidth();
	}
	public void setStrokeWidth(float strokeWidth) {
	    paint.setStrokeWidth(strokeWidth);
	}
	public int getAlpha() {
	    return paint.getAlpha();
	}
	public void setAlpha(int alpha) {
	    paint.setAlpha(alpha);
	}
	public float getX() {
	    return x;
	}
	public void setX(float x) {
	    this.x = x;
	}
	public float getY() {
	    return y;
	}
	public void setY(float y) {
	    this.y = y;
	}
	public int getWidth() {
	    return width;
	}
	public void setWidth(int width) {
	    this.width = width;
	}
	public int getHeight() {
	    return height;
	}
	public void setHeight(int height) {
	    this.height = height;
	}

	public int getTargetLayer() {
	    return targetLayer;
	}
	public void setTargetLayer(int targetLayer) {
	    this.targetLayer = targetLayer;
	}

	public Paint getPaint() {
	    return paint;
	}
	public void setPaint(Paint paint) {
	    this.paint = paint;
	}
	public List<Layer> getLayer(){
		return listLayer;
	}
	public void setLayer(List<Layer> list){
		listLayer = list;
	}
	public Bitmap getScreen() {
		if(listLayer.isEmpty() == true){
			return null;
		}
		Bitmap bmp = Bitmap.createBitmap(listLayer.get(0).getWidth(), listLayer.get(0).getHeight(), Bitmap.Config.ARGB_8888);
		Canvas canvas = new Canvas(bmp);
		for(Layer layer : listLayer){
			canvas.drawBitmap(layer.getBitmap(), layer.getX(), layer.getY(), null);
		}
		
	    return bmp;
	}
	public void addLayer(Bitmap screen) {
	    Layer layer = new Layer(screen);
	    listLayer.add(layer);
	    setTargetLayer(listLayer.size()-1);
	}
}
